//
//  ViewController.m
//  UITableView 16.3.4
//
//  Created by zhangxin on 16/3/4.
//  Copyright © 2016年 zhangxin. All rights reserved.
//

#import "ViewController.h"

//遵循数据源协议
@interface ViewController ()<UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //设置数据源
    self.tableView.dataSource = self;
}


//协议中方法的实现
//1、返回tableview的组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //设置tableview有3组
    return 3;
}

//2.返回行数（每一组的行数）
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //return 3;
    if (section == 0) {
        return 1;
    }
    else if (section == 1)
    {
        return 2;
    }else
    {
        return 3;
    }
}


//3.将数组添加到每一行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //UITableViewCell:每一行的格子
    //indexPath:代表唯一的行
    //indexPath 有两个属性：section row
    //indexPath.section : 获取到组号
    //indexPath.row : 获取到行号
    
    //创建cell
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    //设置数据到cell
  
    
    if (indexPath.section == 0 ) {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"zx";
        }
        
    }else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            cell.textLabel.text = @"yin";

        }else{
            cell.textLabel.text = @"yao";
        }
    }
        else
        {
            if(indexPath.row == 0){
           
                cell.textLabel.text = @"lu";

            }else if(indexPath.row == 1){
                cell.textLabel.text = @"xiao";
            }
            else{
                cell.textLabel.text = @"xin";
            }
        }
    
    cell.imageView.image = [UIImage imageNamed:@"4.jpg"];
    
    return cell;
    
}

- (NSString * )tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0 ) {
        return @"A";
    }else if (section == 1) {
        return @"B";
    }else{
        return @" C";
    }
    
}

- (NSString * )tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    if (section == 0 ) {
        return @"大学";
    }else if (section == 1) {
        return @"高中";
    }else{
        return @"初中";
    }
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
